import 'package:flutter/cupertino.dart';
import 'package:flutter_09_game/base/controller/base_controller.dart';
import 'package:flutter_09_game/base/controller/base_list_controller.dart';
import 'package:flutter_09_game/base/controller/base_list_more_controller.dart';
import 'package:flutter_09_game/generated/locales.g.dart';
import 'package:flutter_09_game/http/http_export.dart';
import 'package:flutter_09_game/pages/deposit/deposit_record/deposit_record_team/deposit_record_team_commission/deposit_record_team_commission_logic.dart';
import 'package:flutter_09_game/pages/deposit/deposit_record/deposit_record_team/deposit_record_team_commission/deposit_record_team_commission_view.dart';
import 'package:flutter_09_game/pages/deposit/deposit_record/deposit_record_team/deposit_record_team_list/deposit_record_team_list_logic.dart';
import 'package:flutter_09_game/pages/deposit/deposit_record/deposit_record_team/deposit_record_team_list/deposit_record_team_list_view.dart';
import 'package:flutter_09_game/pages/deposit/deposit_record/deposit_record_team/deposit_record_team_view.dart';
import 'package:flutter_09_game/pages/deposit/models/model_record_team.dart';
import 'package:flutter_09_game/pages/deposit/utils_deposit.dart';
import 'package:flutter_09_game/pages/main/keep_alive_widget.dart';
import 'package:flutter_09_game/user/app_user_manager.dart';
import 'package:flutter_09_game/utils/log/utils_log.dart';
import 'package:flutter_09_game/utils/utils_other.dart';
import 'package:flutter_date_pickers/flutter_date_pickers.dart';
import 'package:get/get.dart';

class DepositRecordTeamLogic extends BaseController {
  DepositRecordTeamLogic({required this.tag});

  final String tag;

  late RxString selectorTagRx = UtilsOther.recordTeamOptions.first.obs;
  // List<String> options = [
  //   LocaleKeys.funds.tr,
  //   LocaleKeys.hash.tr,
  //   LocaleKeys.game.tr,
  //   LocaleKeys.team.tr,
  // ];

  int currentIndex = 0;

  late final PageController pageController = PageController(initialPage: currentIndex);
  late final List<Widget> pages = UtilsOther.recordTeamOptions.map((value) {
    if (value == LocaleKeys.team.tr) {
      return DepositRecordTeamCommissionPage(tag: tag);
    } else {
      return DepositRecordTeamListPage(type: value + tag,);
    }
    // return KeepAlive(keepAlive: true, child: Container());
  }).toList();

  /// 切换页面索引
  void changeIndex(int index) {
    clog('currentIndex   $currentIndex   $index');
    if (currentIndex == index) return;
    currentIndex = index;

    // WidgetsBinding.instance.addPostFrameCallback((_) {
    //   if (pageController.hasClients) {
    clog('dalksjdklsa $index');
    pageController.jumpToPage(index);
    //   }
    // });
    updateOfCurrentLogic();
  }

  updateOfCurrentLogic() {

    String tagOption = UtilsOther.recordTeamOptions[currentIndex];
    if (tagOption == LocaleKeys.team.tr) {
      if (Get.isRegistered<DepositRecordTeamCommissionLogic>()) {
        Get.find<DepositRecordTeamCommissionLogic>(tag: tag)
            .refreshController
            .requestRefresh();
      }
    } else {
      if (Get.isRegistered<DepositRecordTeamListLogic>(tag: tagOption + tag)) {
        Get.find<DepositRecordTeamListLogic>(tag: tagOption + tag)
            .refreshController
            .requestRefresh();
      }
    }
  }

  @override
  void onReady() {
    // TODO: implement onReady
    super.onReady();
  }

  @override
  void onInit() {
    // TODO: implement onInit
    super.onInit();
  }

  @override
  void onClose() {
    // TODO: implement onClose
    pageController.dispose();
    clog('daslkdjlkasdjlks');
    super.onClose();
  }
}
